<?php

declare(strict_types=1);

namespace app\api\controller;

use app\api\service\GoAffPro as GoAffProService;
use app\facade\Basic;
use think\Request;

class GoAffPro
{
    protected $service;
    protected $request;

    public function __construct(Request $request)
    {
        $this->service = new GoAffProService();
        $this->request = $request;
    }
    /**
     * @describe
     * @author: Bobo
     * @date: 2025-05-12 16:57:42 
     * @param [type] @required
     * @return Renderable
     */
    public function searchAffiliate()
    {
        $res_code = $this->request->param('ref');
        $res = $this->service->searchAffiliate($res_code);
        return Basic::json($res);
    }

    /**
     * @describe
     * @author: Bobo
     * @date: 2025-05-13 17:47:31 
     * @param [type] @required
     * @return Renderable
     */
    public function createAffiliateOrder()
    {
        $orderInfo = [
            'id' => 1193,
            'number' => 'BEMADMIN17468203',
            'total' => 1360,
            'subtotal' => 1360,
            'shipping' => 0,
            'customer' => [
                'id' => 405,
                'name' => '',
                'email' => '947242589@qq.com',
            ],
            'line_items' => [
                [
                    'product_id' => 221,
                    'name' => 'Iceriver KAS KS7 30T 3500W',
                    'quantity' => 1,
                    'price' => 1360,
                ]
            ]
        ];
        $res = $this->service->createAffiliateOrder('{"id":17804457,"ref_code":"azkwfrvw"}', $orderInfo);
        return Basic::json($res);
    }

    /**
     * @describe
     * @author: Bobo
     * @date: 2025-05-13 19:31:27 
     * @param [type] @required
     * @return Renderable
     */
    public function updateAffiliateOrder()
    {
        $status = boolval($this->request->param('status'));
        $orderId = intval($this->request->param('id'));
        $res = $this->service->updateAffiliateOrder($status, $orderId);
        return Basic::json($res);
    }
}
